package org.example.controller;

import org.example.dto.SelectRandomImagesResultDto;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.example.service.IGoodsService;
import org.example.entity.Goods;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2025-03-27
 */
@Controller
@RestController
@RequestMapping("/goods")
public class GoodsController {


    @Autowired
    private IGoodsService iGoodsService;

    @Autowired
    private IGoodsService goodsService;

    @GetMapping(value = "/FindGoods")
    public Map<String, Object> FindGoods( @RequestParam Integer page ,@RequestParam Integer size) {
        Map<String, Object> response = new HashMap<>();
        Integer offset = (page - 1) * size;  // 计算偏移量
        response.put("data", iGoodsService.FindGoods(offset, size));  // 调用分页查询方法
        return response;
    }
    @GetMapping(value = "/F_G_By_Classification")//根据分类查询商品
    public List<Goods> Classification(@RequestParam String gCatagory,@RequestParam String gBrand,@RequestParam Integer page,@RequestParam Integer size) {
        Integer offset = (page - 1) * size;  // 计算偏移量
        List<Goods> goodses = iGoodsService.Classification(gCatagory,gBrand,offset,size);
        return goodses;
    }
    //根据最高或最低价格查询商品
    @GetMapping(value = "/F_G_By_Price")
    public List<Goods> FindGoodsByPrice(@RequestParam String isASC,@RequestParam Integer page,@RequestParam Integer size) {
        Integer offset = (page - 1) * size;  // 计算偏移量
        List<Goods> goodses = iGoodsService.FindGoodsByPrice(isASC,offset,size);
        return goodses;
    }
    //获取轮播图随机图片
    @GetMapping(value = "/GetRandomImages")
    public List<SelectRandomImagesResultDto> GetRandomImages() {
        return goodsService.selectRandomImages();
    }
    //查询商品总数
    @GetMapping(value = "/CountGoods")
    public Integer CountGoods() {
        return goodsService.CountGoods();
    }
}
